<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8"/>
		<title>生产日报表</title>
		<meta name="viewport" content="width=device-width, initial-scale=1"/>
		<meta http-equiv="X-UA-Compatible" content="IE=edge" />
		<meta http-equiv="pragma" content="no-cache"/>
		<meta http-equiv="cache-control" content="no-cache"/>
		<meta http-equiv="expires" content="0"/>	
		<link rel="stylesheet" href="./4/lumen/bootstrap.css" media="screen"/>
		<link rel="stylesheet" href="./_assets/css/custom.min.css"/>
	</head>
<body>
	<div class="container">
		<form>
			<legend>生产日报表</legend>
			<div class="form-group row">
				<label class="col-sm-1 col-form-label" for="inputDefault">工序:</label>
				<div class="col-sm-2">
					<select name="WP" class="form-control" id="WP" type="text">
						<option value="齐纳">齐纳</option>
						<option value="固晶">固晶</option>
						<option value="焊线">焊线</option>
						<option value="点胶">点胶</option>
						<option value="切割">切割</option>
						<option value="分光">分光</option>
						<option value="编带">编带</option>
					</select>
				</div>
			  <label class="col-sm-1 col-form-label" for="inputDefault">班別:</label>
			  <div class="col-sm-1">
			  <input type="radio" class="form-check-input" name="classRadios" id="optionsRadios1" value="A">
				<label class="custom-control-label" for="customRadio1">A</label><br>
			  <input type="radio" class="form-check-input" name="classRadios" id="optionsRadios2" value="B">
				<label class="custom-control-label" for="customRadio1">B</label>
			  </div>
				<button type="button" id="ChaXun" >查詢今天排配</button>
				<!-- 2018-3-14 16:27:31注釋:PHP要切開 -->
				<button type="button" id="ChaXun2" >查昨天B班排配</button>
				<!-- <button type="button" id="DaoChu" >導出</button> -->
			</div>	
			
			<div class="form-group row">
			  <label class="col-sm-1 col-form-label" for="inputDefault">日期:</label>
			  <div class="col-sm-2">
				<input   class="form-control"  id="RiQi" type="text"/>
			  </div>
			  
			  <label class="col-sm-1 col-form-label" for="inputDefault">周別:</label>
			  <div class="col-sm-1">
				<input   class="form-control"  id="ZhouBie" type="text"/>
			  </div>
			  
			  <label class="col-sm-1 col-form-label" for="inputDefault">製表人:</label>
			  <div class="col-sm-2">
				<input   class="form-control"  id="ZhiBiao" type="text"/>
			  </div>
			  
			</div>

			
			<div id="mytable"></div>
			
		</form>
			<div class="form-group row">
			  <div class="col-sm-2">
			  </div>
			  <div class="col-sm-2">
			  </div>
			  <div class="col-sm-2">
			  </div>
			  <div class="col-sm-2">
			  </div>
			  <div class="col-sm-2">
				<button type="button" id="keep" >保存</button>
			  </div>
			  <div class="col-sm-2">
				<button type="button" id="save" >提交</button>
			  </div>
			</div>
			<div class="form-group row">
			</div>
		
		<p class="lead">
			<a class="btn btn-primary btn-lg" href="index.html" role="button">返回</a>
		</p>
	</div>
	
	<link rel="stylesheet" type="text/css" href="./jexcel-master/dist/css/jquery.jexcel.css" />
    <script src="./_vendor/jquery/dist/jquery.min.js"></script>
	<script src="./jexcel-master/dist/js/jquery.jexcel.js"></script>
    <script src="./_vendor/popper.js/dist/umd/popper.min.js"></script>
    <script src="./_vendor/bootstrap/dist/js/bootstrap.min.js"></script>
    <script src="./_assets/js/custom.js"></script>
	
	
	
<script>

	Plan_data = null; 
	//encodeURIComponent編碼
	//decodeURIComponent後端解碼
	//2018-3-8 21:28:30注釋:為了方便修改,將每個字段頭拆成單行.
	//2018-3-9 15:28:25注釋:已保存備份,以下用新方法快速關聯修改畫面
	//var GongXu = encodeURIComponent($("#WP").val());//工序
	
	var DT = $("#RiQi").val();//日期
	console.log(DT);
	
	
	$(document).ready(function (){
		$.ajax({ url: "getPlan.php?GongXu=&BanBie=", 
			dataType : "json",
			success: function(data){
				console.log(data);
				Plan_data = data;
				$('#mytable').jexcel({ data:Plan_data,
					columns: [
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true }
					],		
				
					colHeaders:[
						'ID',
						'訂單號',
						'工序',
						'日期',
						'班別',
						'產品型號',
						'產品<br/>類型',
						'机台号',
						'工单',
						'產品系列',
						'操作员<br/>(工号)',
						'計劃<br/>產能<br/>(K)',
						'实际<br/>產能<br/>(K)',
						'排配<br/>工時<br/>(小时)',
						'实际<br/>工时<br/>(分钟)',
						'待排配<br/>(待機)',
						'日點檢<br/>保養',
						'工單<br/>切換<br/>調机',
						'更換<br/>耗材',
						'冶具<br/>清理',
						'首件',
						'生產<br/>調机',
						'工程<br/>試樣',
						'設備<br/>故障<br/>停機',
						'品質<br/>異常<br/>停線',
						'待料',
						'水電氣<br/>異常',
						'其他<br/>計劃外<br/>停機',
						'未達成原因備註',
						'正常<br/>運轉<br/>時間',
						'可利用<br/>時間',
						'停機<br/>時間<br/>匯總<br/>(f)',
						'理論<br/>工時',
						'UPH<br/>(K/H)',
						'生產<br/>效率',
						'設備<br/>稼動率<br/>((d-f)/d)',
						'產能<br/>達成率',
						'產能<br/>是否<br/>達成',
					],
					
					colWidths:[
						50,
						100,
						60,
						100,
						60,
						150,
						60,
						60,
						100,
						80,
						80,
						80,
						50,
						80,
						60,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						200,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
					]
				
				});
				console.log(Plan_data);
			}
		});
	});
	
	$("#ChaXun").click(function(){
		//按下查詢時，再取值
		var GongXu = encodeURI($("#WP").val());//工序
		var BanBie = $('input[type="radio"][name="classRadios"]:checked').val();//$("#optionsRadios2").val();//班別
		//不允許班別沒有輸入，給定A班。
		console.log(BanBie);
		$.ajax({ url: "getPlan.php?GongXu="+GongXu+"&BanBie="+BanBie,  //+"&DT="+DT
			dataType : "json",
			success: function(data){
				Plan_data = data;
				$('#mytable').jexcel({ data:Plan_data,
					columns: [
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true }
					],		
				
					colHeaders:[
						'ID',
						'訂單號',
						'工序',
						'日期',
						'班別',
						'產品型號',
						'產品<br/>類型',
						'机台号',
						'工单',
						'產品系列',
						'操作员<br/>(工号)',
						'計劃<br/>產能<br/>(K)',
						'实际<br/>產能<br/>(K)',
						'排配<br/>工時<br/>(小时)',
						'实际<br/>工时<br/>(分钟)',
						'待排配<br/>(待機)',
						'日點檢<br/>保養',
						'工單<br/>切換<br/>調机',
						'更換<br/>耗材',
						'冶具<br/>清理',
						'首件',
						'生產<br/>調机',
						'工程<br/>試樣',
						'設備<br/>故障<br/>停機',
						'品質<br/>異常<br/>停線',
						'待料',
						'水電氣<br/>異常',
						'其他<br/>計劃外<br/>停機',
						'未達成原因備註',
						'正常<br/>運轉<br/>時間',
						'可利用<br/>時間',
						'停機<br/>時間<br/>匯總<br/>(f)',
						'理論<br/>工時',
						'UPH<br/>(K/H)',
						'生產<br/>效率',
						'設備<br/>稼動率<br/>((d-f)/d)',
						'產能<br/>達成率',
						'產能<br/>是否<br/>達成',
					],
					
					colWidths:[
						50,
						100,
						60,
						100,
						60,
						150,
						60,
						60,
						100,
						80,
						80,
						80,
						50,
						80,
						60,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						200,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
					]
				
				});
				console.log(Plan_data);
			}
		});
	});
	
	$("#ChaXun2").click(function(){
		//按下查詢時，再取值
		var GongXu = encodeURI($("#WP").val());//工序
		var BanBie = $('input[type="radio"][name="classRadios"]:checked').val();//$("#optionsRadios2").val();//班別
		//不允許班別沒有輸入，給定A班。
		console.log(BanBie);
		$.ajax({ url: "getYPlan.php?GongXu="+GongXu,  //+"&DT="+DT
			dataType : "json",
			success: function(data){
				Plan_data = data;
				$('#mytable').jexcel({ data:Plan_data,
					columns: [
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', wordWrap:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true },
						{ type:'text', readOnly:true }
					],		
				
					colHeaders:[
						'ID',
						'訂單號',
						'工序',
						'日期',
						'班別',
						'產品型號',
						'產品<br/>類型',
						'机台号',
						'工单',
						'產品系列',
						'操作员<br/>(工号)',
						'計劃<br/>產能<br/>(K)',
						'实际<br/>產能<br/>(K)',
						'排配<br/>工時<br/>(小时)',
						'实际<br/>工时<br/>(分钟)',
						'待排配<br/>(待機)',
						'日點檢<br/>保養',
						'工單<br/>切換<br/>調机',
						'更換<br/>耗材',
						'冶具<br/>清理',
						'首件',
						'生產<br/>調机',
						'工程<br/>試樣',
						'設備<br/>故障<br/>停機',
						'品質<br/>異常<br/>停線',
						'待料',
						'水電氣<br/>異常',
						'其他<br/>計劃外<br/>停機',
						'未達成原因備註',
						'正常<br/>運轉<br/>時間',
						'可利用<br/>時間',
						'停機<br/>時間<br/>匯總<br/>(f)',
						'理論<br/>工時',
						'UPH<br/>(K/H)',
						'生產<br/>效率',
						'設備<br/>稼動率<br/>((d-f)/d)',
						'產能<br/>達成率',
						'產能<br/>是否<br/>達成',
					],
					
					colWidths:[
						50,
						100,
						60,
						100,
						60,
						150,
						60,
						60,
						100,
						80,
						80,
						80,
						50,
						80,
						60,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						200,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
						50,
					]
				
				});
				console.log(Plan_data);
			}
		});
	});
	
	$("#keep").click(function(){
	    
		var longdata =$('#mytable').jexcel('getData', false); 
	    //用逗點隔開的字串
		console.log(longdata);
		// 逗點能否 傳到 後端，如果不行，也要變成encodeURI(longdata),搞錯，有不少中文
			//longdata = encodeURI(longdata);
		$.ajax({ 
			type:'POST',
			url: "keep.php",//?nos="+longdata,  //傳一個超長字串到後端
			data:"nos="+JSON.stringify(longdata),
			dataType : "json",
			success: function(data){
				cconsole.log(data);
			}
		});
	});
	
	
	
	//默認日期(因為JS沒有日期格式化函數)
	var date = new Date
	var mm = ""
	var dd = ""
	if ((date.getMonth()+1)>9){
		mm=(date.getMonth()+1)
	}else{
		mm=0+""+(date.getMonth()+1)
	};
	if ((date.getDate())>9){
		dd=(date.getDate())
	}else{
		dd=0+""+(date.getDate())
	};
	//2018-3-8
	//2018-03-08
	$("#RiQi").val(date.getFullYear()+"-"+mm+"-"+dd);
	
	$("#ZhouBie").val(getWeekOfYear(date))
	
	
	//一天含86,400,000毫秒(24*60*60*1000)
	//公式計算获取本周是一年中的第几周
	function getWeekOfYear(date){
	    var d1 = date;
	    var d2 = new Date(date.getFullYear(), 0, 1);
	    var d = Math.round((d1 - d2) / 86400000);
	    return Math.ceil((d + ((d2.getDay() + 1) - 1)) / 7);
	};
</script>
	
</body>
</html>
